//
//  DelegatePayView.m
//  项目三
//
//  Created by rimi on 15/10/9.
//  Copyright (c) 2015年 rimi. All rights reserved.
//

#import "DelegatePayView.h"


@interface DelegatePayView() {

    UIButton *_waterBtn;
    UIButton *_electricBtn;
    UIButton *_gasBtn;
    UIButton *_telecom;   /**< 电信 */
    UIButton *_unicom;    /**< 联通 */
    UIButton *_mobile;    /**< 移动 */
    UIButton *_east;      /**< 东方有线 */
}
@property (nonatomic, strong) UIButton *photoBtn;
@property (nonatomic, strong) UIButton *judgeBtn;
@property (nonatomic, strong) UIButton *confirmBtn;
@property (nonatomic, strong) UIButton *chooseAllBtn;
@property (nonatomic, strong) UIButton *confirmPayBtn;
@property (nonatomic, strong) UIImageView *textfieldView;
@property (nonatomic, strong) UITextField *textfield;
@property (nonatomic, strong) UIImageView *tableImage;
@property (nonatomic, strong) UILabel *moneyLabel;
@property (nonatomic, strong) UILabel *yuanLabel;
@property (nonatomic, strong) UILabel *allMoney;

- (void)initializeAppearence;
@end

@implementation DelegatePayView

#pragma mark - init
- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initializeAppearence];
    }
    return self;
}

- (instancetype)init {
    self = [super init];
    if (self) {
        [self initializeAppearence];
    }
    return self;
}

- (void)initializeAppearence {

    self.backgroundColor = COLOR(205, 205, 205, 1);
    NSArray *imageArr = @[@"未选中-水", @"未选中-电", @"未选中-煤气", @"未选中-电信",@"未选中-联通", @"未选中-移动"];
    NSArray *selectedImageArr = @[@"选中 水", @"选中 电", @"选中 煤气费", @"选中 电信",@"选中 联通", @"选中 移动"];
    
    for (int i = 0; i < 6; i++) {
        UIButton *btn = [[UIButton alloc] initWithFrame:DHFlexibleFrame(CGRectMake(60 + (i % 4) * (122 + 23), 100 + (i / 4) * (75 + 30), 122, 75))];
        btn.selected = NO;
        [btn setImage:[UIImage imageNamed:imageArr[i]] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:selectedImageArr[i]] forState:UIControlStateSelected];
        btn.tag = 100 + i;
        [btn addTarget:self action:@selector(actionOnBtn:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
    }
    
    _waterBtn = (UIButton *)[self viewWithTag:100];
    _electricBtn = (UIButton *)[self viewWithTag:101];
    _gasBtn = (UIButton *)[self viewWithTag:102];
    _telecom = (UIButton *)[self viewWithTag:103];
    _unicom = (UIButton *)[self viewWithTag:104];
    _mobile = (UIButton *)[self viewWithTag:105];
    
    _east = [[UIButton alloc] initWithFrame:DHFlexibleFrame(CGRectMake(350, 205, 145, 75))];
    [_east setImage:[UIImage imageNamed:@"未选中-东方有线"] forState:UIControlStateNormal];
    [_east setImage:[UIImage imageNamed:@"选中 东方有线"] forState:UIControlStateSelected];
    _east.tag = 106;
    [_east addTarget:self action:@selector(actionOnBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_east];
    
    [self addSubview:self.photoBtn];
    [self addSubview:self.judgeBtn];
    [self addSubview:self.confirmBtn];
    [self addSubview:self.chooseAllBtn];
    [self addSubview:self.confirmPayBtn];
    [self addSubview:self.textfieldView];
    [self addSubview:self.textfield];
    [self addSubview:self.moneyLabel];
    [self addSubview:self.yuanLabel];
    [self addSubview:self.tableImage];
    [self addSubview:self.allMoney];
}

#pragma mark - action on btn
- (void)actionOnBtn:(UIButton *)button {

    switch (button.tag) {
        case 100:
        {
            _waterBtn.selected = YES;
            _electricBtn.selected = NO;
            _gasBtn.selected = NO;
            _telecom.selected = NO;
            _unicom.selected = NO;
            _mobile.selected = NO;
            _east.selected = NO;
        }
            break;
        case 101:
        {
            _waterBtn.selected = NO;
            _electricBtn.selected = YES;
            _gasBtn.selected = NO;
            _telecom.selected = NO;
            _unicom.selected = NO;
            _mobile.selected = NO;
            _east.selected = NO;
        }
            break;
        case 102:
        {
            _waterBtn.selected = NO;
            _electricBtn.selected = NO;
            _gasBtn.selected = YES;
            _telecom.selected = NO;
            _unicom.selected = NO;
            _mobile.selected = NO;
            _east.selected = NO;
        }
            break;
        case 103:
        {
            _waterBtn.selected = NO;
            _electricBtn.selected = NO;
            _gasBtn.selected = NO;
            _telecom.selected = YES;
            _unicom.selected = NO;
            _mobile.selected = NO;
            _east.selected = NO;
        }
            break;
        case 104:
        {
            _waterBtn.selected = NO;
            _electricBtn.selected = NO;
            _gasBtn.selected = NO;
            _telecom.selected = NO;
            _unicom.selected = YES;
            _mobile.selected = NO;
            _east.selected = NO;
        }
            break;
        case 105:
        {
            _waterBtn.selected = NO;
            _electricBtn.selected = NO;
            _gasBtn.selected = NO;
            _telecom.selected = NO;
            _unicom.selected = NO;
            _mobile.selected = YES;
            _east.selected = NO;
        }
            break;
        case 106:
        {
            _waterBtn.selected = NO;
            _electricBtn.selected = NO;
            _gasBtn.selected = NO;
            _telecom.selected = NO;
            _unicom.selected = NO;
            _mobile.selected = NO;
            _east.selected = YES;
        }
            break;
        default:
            break;
    }
}
//拍码
- (void)actionOnPhotoBtn {
    
    
}
//识别
- (void)actionOnJudegBtn {
    
    
}
//确定
- (void)actionOnConfirmBtn {
    
    
}
//全选
- (void)actionOnChooseAllBtn {
    
    
}
//确认缴费
- (void)actionOnConfirmPayBtn {
    
    
}
#pragma mark - getter
- (UIButton *)photoBtn {
    
    if (!_photoBtn) {
        _photoBtn = ({
            
            UIButton *button = [[UIButton alloc] initWithFrame:DHFlexibleFrame(CGRectMake(73, 313, 120, 47))];
            [button setImage:[UIImage imageNamed:@"拍码-1"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(actionOnPhotoBtn) forControlEvents:UIControlEventTouchUpInside];
            button;
        });
    }
    return _photoBtn;
}
- (UIButton *)judgeBtn {
    
    if (!_judgeBtn) {
        _judgeBtn = ({
            
            UIButton *button = [[UIButton alloc] initWithFrame:DHFlexibleFrame(CGRectMake(570, 322, 83, 30))];
            [button setImage:[UIImage imageNamed:@"条码识别"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(actionOnJudegBtn) forControlEvents:UIControlEventTouchUpInside];
            button;
            
        });
    }
    return _judgeBtn;
}
- (UIButton *)confirmBtn {
    
    if (!_confirmBtn) {
        _confirmBtn = ({
            
            UIButton *button = [[UIButton alloc] initWithFrame:DHFlexibleFrame(CGRectMake(265, 447, 122, 40))];
            [button setImage:[UIImage imageNamed:@"确定1"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(actionOnConfirmBtn) forControlEvents:UIControlEventTouchUpInside];
            button;
            
        });
    }
    return _confirmBtn;
}
- (UIButton *)chooseAllBtn {
    
    if (!_chooseAllBtn) {
        _chooseAllBtn = ({
            
            UIButton *button = [[UIButton alloc] initWithFrame:DHFlexibleFrame(CGRectMake(175, 825, 120, 42))];
            [button setImage:[UIImage imageNamed:@"全选"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(actionOnChooseAllBtn) forControlEvents:UIControlEventTouchUpInside];
            button;
        });
    }
    return _chooseAllBtn;
}
- (UIButton *)confirmPayBtn {
    
    if (!_confirmPayBtn) {
        _confirmPayBtn = ({
            
            UIButton *button = [[UIButton alloc] initWithFrame:DHFlexibleFrame(CGRectMake(375, 825, 120, 42))];
            [button setImage:[UIImage imageNamed:@"确定缴费"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(actionOnConfirmPayBtn) forControlEvents:UIControlEventTouchUpInside];
            button;
        });
    }
    return _confirmPayBtn;
}
- (UIImageView *)textfieldView {

    if (!_textfieldView) {
        _textfieldView = ({
        
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:DHFlexibleFrame(CGRectMake(206, 323, 355, 30))];
            imageView.image = [UIImage imageNamed:@"自定义输入框"];
            imageView;
        });
    }
    return _textfieldView;
}
- (UITextField *)textfield {

    if (!_textfield) {
        _textfield = ({
        
            UITextField *textField = [[UITextField alloc] initWithFrame:DHFlexibleFrame(CGRectMake(215, 325, 345, 25))];
//            textField.layer.borderWidth = 1;
            textField.layer.borderColor = [UIColor clearColor].CGColor;
            textField;
        });
    }
    return _textfield;
}
- (UILabel *)moneyLabel {

    if (!_moneyLabel) {
        _moneyLabel = ({
        
            UILabel *label = [[UILabel alloc] initWithFrame:DHFlexibleFrame(CGRectMake(145, 385, 45, 20))];
            label.text = @"金额:";
            label.textAlignment = NSTextAlignmentCenter;
            
            label;
        });
    }
    return _moneyLabel;
}
- (UILabel *)yuanLabel {

    if (!_yuanLabel) {
        _yuanLabel = ({
        
            UILabel *label = [[UILabel alloc] initWithFrame:DHFlexibleFrame(CGRectMake(210, 385, 250, 20))];
            label.text = @"元";
            label.textAlignment = NSTextAlignmentRight;
            
            label;
        });
    }
    return _yuanLabel;
}
- (UIImageView *)tableImage {

    if (!_tableImage) {
        _tableImage = ({
        
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:DHFlexibleFrame(CGRectMake(70, 505, 580, 300))];
            imageView.image = [UIImage imageNamed:@"代理缴费表"];
            imageView;
        });
    }
    return _tableImage;
}
- (UILabel *)allMoney {

    if (!_allMoney) {
        _allMoney = ({
        
            UILabel *label = [[UILabel alloc] initWithFrame:DHFlexibleFrame(CGRectMake(540, 772, 70, 25))];
            label.text = @"0.00元";
            label.textAlignment = NSTextAlignmentCenter;
            
            label;

        });
    }
    return _allMoney;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    [self endEditing:YES];
}
@end
